<template>
  <div>
    <h3>{{ num }}</h3>
    <el-button @click="btnClick">点击+1</el-button>
    <h4>{{ $store.state.user.test }}</h4>
    <el-button @click="$store.commit('user/SET_TEST',Date.now())">修改test</el-button>
  </div>
</template>
<script>
// 浏览器存储：localStorage sessionStorage cookie
// cookie:主动参与接口请求
// js-cookie  get  set remove
// 持久化：
//  1:值改变了就存储到浏览器
//  2：初始值读取浏览器存储
import jsCookie from 'js-cookie'
export default {
  data() {
    return {
      num: +jsCookie.get('num') || 1
    }
  },
  methods: {
    btnClick() {
      this.num++
      jsCookie.set('num', this.num)
    }
  }
}
</script>
<style>
</style>
